package com.LeeCode;

public class Code2772 {
    public static void main(String[] args) {
        int[] nums = {0, 72};
        int k = 2;
        System.out.println(new Code2772().checkArray(nums, k));
    }

    public boolean checkArray(int[] nums, int k) {
        int n = nums.length;
        int[] diff = new int[n + 1];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += diff[i];
            int actualVal = nums[i] + sum;
            if (actualVal == 0) continue;

            if (actualVal < 0) return false;
            if (i + k > n) return false;

            diff[i + k] += actualVal;
            sum -= actualVal;
        }
        return true;
    }
}
